﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.Domain.Entities;
using SeaBattle.Domain.Abstract;

namespace SeaBattle.Domain.Concrete.Services
{
    public class FakeGameService : IGameService
    {
        private IPlayerService playerService;
        private IGameRepository gameRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="FakeGameService"/> class.
        /// </summary>
        /// <param name="playerService">The player service.</param>
        /// <param name="gameRepository">The game repository.</param>
        /// <remarks></remarks>
        public FakeGameService(IPlayerService playerService, IGameRepository gameRepository)
        {
            this.gameRepository = gameRepository;
            this.playerService = playerService;
        }

        /// <summary>
        /// Gets the opened games.
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public IEnumerable<Game> GetOpenedGames()
        {
            return gameRepository.Games
                .Where(x => x.Opened)
                .OrderBy(x => x.Preset);
        }

        /// <summary>
        /// Gets the participants player games.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public IEnumerable<Game> GetParticipantsPlayerGames(Player player)
        {
            return gameRepository.Games
                .Where(x => (x.Creator == player || x.Opponent == player))
                .OrderByDescending(x=>x.Created);
        }
    }
}
